package com.example.suspensionbardemo

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.fragment.app.Fragment
import com.example.suspensionbardemo.R
import com.example.suspensionbardemo.adapter.ViewPager2Adapter
import com.example.suspensionbardemo.adapter.ViewPagerAdapter
import com.example.suspensionbardemo.databinding.ActivityRefreshBinding
import com.example.suspensionbardemo.databinding.ActivityRefreshViewPager1Binding
import com.example.suspensionbardemo.fragment.RecyclerViewFragment
import com.google.android.material.tabs.TabLayoutMediator

class RefreshViewPager1Activity : AppCompatActivity() {

    lateinit var binding: ActivityRefreshViewPager1Binding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityRefreshViewPager1Binding.inflate(layoutInflater)
        setContentView(binding.root)

        binding.titleBar.tvTitle.setText("ViewPager1")

        initListener();

        val pagerAdapter =
            ViewPagerAdapter(
                supportFragmentManager,
                getPageFragments()
            );
        binding.viewpager.adapter = pagerAdapter;

        binding.tablayout.setupWithViewPager(binding.viewpager)

        /*  TabLayoutMediator(binding.tablayout, binding.viewpager) { tab, position ->
              tab.text = labels[position]
          }.attach()*/
    }


    private fun initListener() {
        binding.refreshLayout.setOnRefreshListener {
            println("RefreshActivity.initListener")
            binding.refreshLayout.finishRefresh();

        }
    }

    private fun getPageFragments(): List<Fragment>? {
        val data: MutableList<Fragment> = ArrayList()
        data.add(RecyclerViewFragment())
        data.add(RecyclerViewFragment())
        data.add(RecyclerViewFragment())
        data.add(RecyclerViewFragment())
        return data
    }

}